-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Trap Ctrl-C in the REPL: if no command is running clear the prompt, if some command is running ask for confirmation before exiting #24127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
scala> while true do
| Thread.sleep(1000)
| println("still alive!")
|
still alive!
still alive!
^C
Interrupting running thread, Ctrl-C again to terminate the REPL Process
java.lang.InterruptedException: sleep interrupted
at java.base/java.lang.Thread.sleep(Native Method)
... 32 elided
scala> Nice! |
Edit: it has to be a true infinite loop, with no yielding, for double interrupt to work (so no sleep) |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
I wonder if/how we could test this in a meaningful manner... can be as a follow-up, I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, LGTM!
Co-authored-by: Oliver Bračevac <bracevac@users.noreply.github.com>
@bracevac you merged it without squashing, you probably should force push and clean up the history before it gets buried under further commits otherwise the git commit history is going to be full of trash |
…f some command is running ask for confirmation before exiting (#24127) This ports over one of the other Ammonite features to the Scala 3 REPL, making it behave much more similarly to other prompt environment (Bash, Python, etc.): - If there is no code running, `Ctrl-C` just resets the prompt without exiting - If there is code running, `Ctrl-C` first interrupts the thread to try and force a gentle exit. A second `Ctrl-C` would then terminate the process. Unfortunately we will no longer be able to terminate the thread forcefully, as `Thread.stop` is busted Java >20 (see com-lihaoyi/Ammonite#1379), so using `Thread.interrupt` and `sys.exit` is the best we have Tested manually using `bin/scala`. Doesn't work in `sbt repl` due to SBT also intercepting the signal, but that's a separate issue we can follow up later
Sorry about that! The cascade of approvals made me not look too closely. We can't change it now. That reminds me: I'm not aware what's our official etiquette for PRs. Perhaps, an accompanying message that communicates if merging is desired or not would be nice. |
This ports over one of the other Ammonite features to the Scala 3 REPL, making it behave much more similarly to other prompt environment (Bash, Python, etc.):
Ctrl-C
just resets the prompt without exitingCtrl-C
first interrupts the thread to try and force a gentle exit. A secondCtrl-C
would then terminate the process.Unfortunately we will no longer be able to terminate the thread forcefully, as
Thread.stop
is busted Java >20 (see com-lihaoyi/Ammonite#1379), so usingThread.interrupt
andsys.exit
is the best we haveTested manually using
bin/scala
. Doesn't work insbt repl
due to SBT also intercepting the signal, but that's a separate issue we can follow up later